﻿using System;
using System.Web.UI;
using VitCode.BaseDataPageCreator;
using VitCode.Castle.DataAccess;
using VitCode.ObjectResolutionHelper;
using VitCode.Web.UI.WebControls;

namespace CRS.Web.UserControls
{
    public partial class ShowTwoProChildObjSetCtl : UserControl
    {
        private BaseDataAccess m_Acc = new BaseDataAccess();
        private PageLoadHelper m_LoadHelper = new PageLoadHelper("");

        public string ObjClassName
        {
            get { return hdnClassName.Value; }
            set { hdnClassName.Value = value; }
        }

        public string ObjTypeName
        {
            get { return hdnTypeName.Value; }
            set { hdnTypeName.Value = value; }
        }

        public string ObjKeyProName
        {
            get { return hdnKeyProName.Value; }
            set { hdnKeyProName.Value = value; }
        }

        public string ObjShowProName
        {
            get { return hdnShowProName.Value; }
            set { hdnShowProName.Value = value; }
        }

        public string ObjShowProName2
        {
            get { return hdnShowProName2.Value; }
            set { hdnShowProName2.Value = value; }
        }

        public object ObjKeyProVal
        {
            get { return txtObjId.Text; }
            set
            {
                if (value != null)
                {
                    txtObjId.Text = m_LoadHelper.GetProObjStringValue(ObjKeyProName, value);
                    hdnKeyProVal.Value = txtObjId.Text;

                }
            }
        }

        public object ObjShowProVal
        {
            get { return txtObjShowVal.Text; }
            set
            {
                if (value != null)
                {
                    txtObjShowVal.Text = m_LoadHelper.GetProObjStringValue(ObjShowProName, value);
                    hdnShowProVal.Value = txtObjShowVal.Text;
                    txtObjShowVal2.Text = m_LoadHelper.GetProObjStringValue(ObjShowProName2, value);
                    hdnShowProVal2.Value = txtObjShowVal2.Text;
                }
            }
        }

        public object ObjShowProVal2
        {
            get { return txtObjShowVal2.Text; }
            set
            {
                if (value != null)
                {
                    txtObjShowVal2.Text = m_LoadHelper.GetProObjStringValue(ObjShowProName2, value);
                    hdnShowProVal2.Value = txtObjShowVal2.Text;
                }
            }
        }

        public string ConditionString
        {
            get { return hdnConditionString.Value; }
            set { hdnConditionString.Value = value; }
        }

        public string OtherCtlContext
        {
            get { return hdnOtherCtlContext.Value; }
            set { hdnOtherCtlContext.Value = value; }
        }

        public bool Enabled
        {
            get { return txtObjShowVal.Enabled; }
            set 
            { 
                txtObjShowVal.Enabled = value;
                txtObjShowVal2.Enabled = value;
                ibtSeach.Enabled = value;
            }
        }

        private void ShowDialog()
        {
            var strHttpHeadPath = UrlHelper.GetHttpHeadPath();
            string selectPageUrlValue = strHttpHeadPath+"/BaseData/SelObjList.aspx";
            var tempWin = new Window(Page, ObjClassName + "选择页面")
            {
                Width = 800,
                Height = 600,
                Scrollbars = true,
                Status = true
            };
            var reValues = new[] { txtObjId.ClientID, txtObjShowVal.ClientID,txtObjShowVal2.ClientID, hdnKeyProVal.ClientID, hdnShowProVal.ClientID,hdnShowProVal2.ClientID };
            selectPageUrlValue += "?" + BaseDataKeyInfo.CLASS_NAME + "=" + ObjClassName;
            if (ObjTypeName.Length > 0)
                selectPageUrlValue += "&" + BaseDataKeyInfo.TYPE_NAME + "=" + ObjTypeName;
            if (ObjShowProName.Length > 0)
                selectPageUrlValue += "&" + BaseDataKeyInfo.KEY_CONTEXT + "=" + ObjShowProName + ":1," + ObjShowProName2 + ":2," + ObjKeyProName + ":3," + ObjShowProName + ":4," + ObjShowProName2 + ":5";
            if (ObjKeyProName.Length > 0)
                selectPageUrlValue += "&" + BaseDataKeyInfo.KEY_PROPERTY + "=" + ObjKeyProName + ":0";
            
            if (OtherCtlContext.Length > 0)
                selectPageUrlValue += "&" + BaseDataKeyInfo.OTHER_CTL_CONTEXT + "=" + OtherCtlContext;
            if (ConditionString.Length > 0)
            {
                var val = ConditionString;
                Session[selectPageUrlValue + BaseDataKeyInfo.CONDITION_STRING] = val;
            }
            tempWin.ShowModalDialog(selectPageUrlValue, ibtSeach,reValues);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (txtObjId.Text.Length == 0 && hdnKeyProVal.Value.Length > 0)
                txtObjId.Text = hdnKeyProVal.Value;
            if (txtObjShowVal.Text.Length == 0 && hdnShowProVal.Value.Length > 0)
                txtObjShowVal.Text = hdnShowProVal.Value;
            if (txtObjShowVal2.Text.Length == 0 && hdnShowProVal2.Value.Length > 0)
                txtObjShowVal2.Text = hdnShowProVal2.Value;
            ShowDialog();
        }
    }
}
